package test.study.concurrent.thread._7_fork_join;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.TimeUnit;

@Slf4j
public class _3_ForkJoin_Main {

    /* worker thread factory */
    private static ForkJoinPool.ForkJoinWorkerThreadFactory FACTORY = (pool) -> {
        ForkJoinWorkerThread t = ForkJoinPool.defaultForkJoinWorkerThreadFactory
                .newThread(pool);
        //t.setName("bbbbbb");
        return t;
    };
    /* uncaught exception handler */
    private static Thread.UncaughtExceptionHandler HANDLER = (thread, throwable) -> {
        log.info("aaaaaa");
    };
    /* fork join pool */
    private static ForkJoinPool POOL = new ForkJoinPool(10,
            FACTORY,
            HANDLER,
            true);

    public static void main(String[] args) {
        log.info("main thread");

        POOL.execute(() -> {
            log.info("sub thread");
        });

        ThreadUtil.sleep(3, TimeUnit.SECONDS);
    }
}
